<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>登录</title>
    <link href="css/login.css" type="text/css" rel="stylesheet">
    <link href="layui/css/layui.css">
</head>
<body>
<div class="top">必普OA&nbsp;·&nbsp;用数据改变未来</div>
<div class="content">
    <div class="login">
        <form id="login-form" method="post" onsubmit="return false;">
            <div class="title">登录</div>
            <div class="line">
                <img class="smallImg" src="img/login/icon1.png"/>
                <input id="username" name="username" placeholder="请输入账号" type="text" autocomplete="off" autofocus>
            </div>
            <div class="line">
                <img class="smallImg" src="img/login/icon2.png"/>
                <input id="password" name="password" placeholder="请输入密码" type="password"
                       autocomplete="off">
            </div>
            <button type="submit" onclick="login(this)" class="logBut">登&nbsp;&nbsp;录</button>
        </form>
    </div>
</div>
</body>
<script src="js/libs/jquery-2.1.1.min.js"></script>
<script src="js/common.js"></script>
<script src="layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['layer'], function () {
        var layer = layui.layer;
    });
    // $(function  () {
    // 	$('#username').focus();
    // })
    if (top != self) {
        parent.location.href = '/login.html';
    }

    var user = loginInfo();
    if (user != "") {
        location.href = '/';
    }

    function login(obj) {
        $(obj).attr("disabled", true);

        var username = $.trim($('#username').val());
        var password = $.trim($('#password').val());
        if (username == "" || password == "") {
            // $("#info").html('用户名或者密码不能为空');
            layer.msg('用户名或者密码不能为空');
            $(obj).attr("disabled", false);
        } else {
            $.ajax({
                type: 'post',
                url: '/sys/login',
                data: $("#login-form").serialize(),
                success: function () {
                    location.href = '/';
                },
                error: function (xhr, textStatus, errorThrown) {
                    var msg = xhr.responseText;
                    var response = JSON.parse(msg);
                    // $("#info").html(response.message);
                    layer.msg(response.message);
                    $(obj).attr("disabled", false);
                }
            });
        }
    }
</script>
</html>